//
//  JGRightMenuController.m
//  Netease_Project
//
//  Created by JJetGu on 15-6-19.
//  Copyright (c) 2015年 JJetGu. All rights reserved.
//

#import "JGRightMenuController.h"
#import "JGRightMenuCenterViewRow.h"

@interface JGRightMenuController ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UIView *centerView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@end

@implementation JGRightMenuController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 1.填充中间的内容
    [self setupCenterView];
    
    // 2.填充底部的内容
    [self setupBottomView];
    
}

/**
 *  填充中间的内容
 */
- (void)setupCenterView
{
    JGRightMenuCenterViewRow *row =[self setupCenterViewRow:@"商城 能赚能花，土豪当家" icon:@"promoboard_icon_mall"];
    [self setupCenterViewRow:@"活动 4.0发布会粉丝招募" icon:@"promoboard_icon_activities"];
    [self setupCenterViewRow:@"应用 金币从来都是这送的" icon:@"promoboard_icon_apps"];
    
    //确定centerView的最终高度---但要去除xib中的auto layout
    self.centerView.height = self.centerView.subviews.count * row.height;
}

- (JGRightMenuCenterViewRow *)setupCenterViewRow:(NSString *)title icon:(NSString *)icon
{
    JGRightMenuCenterViewRow *rowView = [JGRightMenuCenterViewRow centerViewRow];
    rowView.icon = icon;
    rowView.title = title;
    rowView.y = rowView.height * self.centerView.subviews.count;
    [self.centerView addSubview:rowView];
    return rowView;
}
/**
 *  填充底部的内容
 */
- (void)setupBottomView
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)didShow
{
    // 让头像旋转
    //第一种动画
//    [UIView animateWithDuration:1.0 animations:^{
//        self.iconView.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 1, 0);
//    } completion:^(BOOL finished) {
//        self.iconView.image = [UIImage imageNamed:@"user_defaultgift"];
//        
//        [UIView animateWithDuration:1.0 animations:^{
//            self.iconView.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
//        }];
//    }];

    //第二种动画（这种比较多,也比较高级和灵活）//参考链接：http://blog.163.com/wangy_0223/blog/static/45014661201222694654895/
//    CATransition
//    CATransition *anim = [CATransition animation];
//    anim.duration = 1.0;
//    anim.type = @"rippleEffect";
//    [self.iconView.layer addAnimation:anim forKey:nil];

    //第三种动画
    [UIView transitionWithView:self.iconView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        self.iconView.image = [UIImage imageNamed:@"user_defaultgift"];
    } completion:^(BOOL finished) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView transitionWithView:self.iconView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
                self.iconView.image = [UIImage imageNamed:@"default_avatar"];
            } completion:nil];
        });
    }];
}

@end
